{% extends "zato/index.html" %}
{% load extras %}

{% block html_title %}Groups{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">
    <style type="text/css">
        .ui-dialog-titlebar {
            padding-bottom:10px !important;
        }
    </style>
{% endblock %}

{% block "extra_js" %}

    {% comment %} jQuery {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.tablesorter.min.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.alerts.min.js"></script>

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/groups/index.js"></script>

    <script nonce="{{ CSP_NONCE }}">
    $.fn.zato.data_table.get_columns = function() {
        return [
            '_numbering',
            '_selection',

            // ------ 1 ------ //
            'name',
            '_members',
            '_members_visit',

            // ------ 2 ------ //
            '_clone',
            '_edit',
            '_delete',
            'id',

            // ------ 3 ------ //
            'group_type',
            'is_active',
        ]
    }
    </script>

{% endblock %}

{% block "content" %}
<h2 class="zato">Groups : {{ group_type_name_title }}</h2>

{% if not zato_clusters %}
    {% include "zato/no-clusters.html" %}
{% else %}

    <div id="user-message-div" style='display:none'><pre id="user-message" class="user-message"></pre></div>

{% include "zato/search-form.html" with page_prompt="Show groups"%}

    {% if cluster_id %}
        <div class='page_prompt' style="clear:left">
            <a href="javascript:$.fn.zato.groups.create()">Create a new group</a>
        </div>

        <div id="markup">
            <table id="data-table">
                <thead>
                    <tr class='ignore'>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>

                        {% comment %} 1 {% endcomment %}
                        <th><a href="#">Name</a></th>
                        <th><a href="#">Members</a></th>
                        <th>&nbsp;</th>

                        {% comment %} 2 {% endcomment %}
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                        {% comment %} 3 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                </thead>

                <tbody>
                {% if items %}
                {% for item in items %}
                    <tr class="{% cycle 'odd' 'even' %}" id='tr_{{ item.id }}'>
                        <td class='numbering'>&nbsp;</td>
                        <td class="impexp"><input type="checkbox" /></td>

                        {% comment %} 1 {% endcomment %}
                        <td>{{ item.name }}</td>
                        <td id="group_member_count_{{ item.id }}">{{ member_count|bunchget:item.id }}</td>
                        <td><a href="{% url "groups-members-manage" item.type item.id %}?cluster={{ cluster_id|default:"1" }}">Go to members</a></td>

                        {% comment %} 2 {% endcomment %}
                        <td>
                            {% if False %}
                            <a href="javascript:$.fn.zato.groups.clone('{{ item.id }}')">Clone</a>
                            {% else % }
                            {% endif %}
                        </td>
                        <td><a href="javascript:$.fn.zato.groups.edit('{{ item.id }}')">Edit</a></td>
                        <td><a href="javascript:$.fn.zato.groups.delete_('{{ item.id }}')">Delete</a></td>
                        <td class='ignore item_id_{{ item.id }}'>{{ item.id }}</td>

                        {% comment %} 3 {% endcomment %}
                        <td class='ignore'>{{ item.type }}</td>
                        <td class='ignore'>{{ item.is_active }}</td>

                    </tr>
                {% endfor %}
                {% else %}
                    <tr class='ignore'>
                        <td colspan='9'>No results</td>
                    </tr>
                {% endif %}

                </tbody>
            </table>
        </div>

{% include "zato/paginate/action-panel.html" %}

        <div id="create-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "groups-create" %}" method="post" id="create-form">
                    <table class="form-data">
                        <tr>
                            <td style="vertical-align:middle;width:10%">
                                <label for="id_name">
                                Name
                                </label>
                            </td>
                            <td>{{ create_form.name }}</td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" id="cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                    <input type="hidden" id="group_type" name="group_type" value="{{ group_type }}" />
                </form>
            </div>
        </div>

        <div id="edit-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "groups-edit" %}" method="post" id="edit-form">
                    <table class="form-data">
                        <tr>
                            <td style="vertical-align:middle;width:10%">
                                <label for="id_name">
                                Name
                                </label>
                            </td>
                            <td>{{ edit_form.name }}</td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" id="id_edit-cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                    <input type="hidden" id="id_edit-group_type" name="group_type" value="{{ group_type }}" />
                    <input type="hidden" id="id_edit-id" name="id" />
                </form>
            </div>
        </div>

        {% endif %}


{% endif %}{% comment %}not zato_clusters{% endcomment %}

{% endblock %}
